/**
 * @Author: cest
 * @Date: 2022-07-26 16:00:24
 * @LastEditTime: 2023-04-03 10:50:12
 * @LastEditors: cest cestrmail@163.com
 * @FilePath: /uni-preset-vue-cli-extension-park/src/store/modules/demo/VuexDemo.js
 * @Description: vuex demo
 */

export const MAP = {
NAMESPACED:'demo/VuexDemo',
INCREMENT: 'INCREMENT',
ASYNC_GET_LIST: 'ASYNC_GET_LIST',
APP_TITLE:'APP_TITLE',
COUNT: 'COUNT',
FULL_NAME: 'FULL_NAME'
}
export default {
  namespaced: true,
  state: {
    // vue data
    count: 0,
    appTitle: '应用标题',
    firstName: 'zhuangli',
    lastName: 'qin'
  },
  getters: {
    [MAP.FULL_NAME](state, getters) {
      return state.firstName + state.lastName
    }
  },
  mutations: {
    // vue methods
    // 变更 count 累加
    [MAP.INCREMENT](state, payload) {
      console.log('increment state', state)
      console.log('increment payload', payload)
      const n = payload || 1
      state.count += n
    }
  },
  actions: {
    [MAP.ASYNC_GET_LIST](context, payload) {
      console.log('asyncGetList context', context)
      console.log('asyncGetList payload', payload)
      setTimeout(() => {
        // 500 毫秒以后执行
        console.log('asyncGetList')
      }, 5000)
    }
  }
}
